#ifndef IMAGE_PLOT_DATA_H
#define IMAGE_PLOT_DATA_H

/**
* @file imagePlotData.h
*/

#include <qwt_interval.h>
#include <qwt_raster_data.h>
#include <vector>

namespace spectrum {

/**
* @class ImagePlotData
*
* @brief
*
* @details
* QwtRasterData (similar to QwtData) is the link between the application data
* and the QwtRasterItem (guess here a spectrogram), that is responsible for
* displaying the data.
*
* When the raster item needs to render its image it calculates the position of
* each pixel and asks the raster data object for a value at this position. This
* value is mapped into a colour using the value range, that is also provided by
* the data object.
*/

class ImagePlotData: public QwtRasterData
{
    public:
        /// Constructs an image plot data object.
        ImagePlotData() : QwtRasterData() {}

        /// Destroys the image plot data object.
        ~ImagePlotData() {}

    public:
        /// Set the data to be held in the raster.
        void setData(float const * data, const unsigned nX, const unsigned nY);

        /// Clone the data in the raster.
        QwtRasterData* copy() const;

        /// Set the x range to display.
        void setRangeX(double min, double max);

        /// Set the y range to display.
        void setRangeY(double min, double max);

        int column(double x) const;
        int row(double y) const;

        QwtInterval xRange() const { return _xRange; }
        QwtInterval yRange() const { return _yRange; }
        QwtInterval ampRange() const { return _ampRange; }

        unsigned sizeX() const { return _sizeX; }
        unsigned sizeY() const { return _sizeY; }

        double intervalX() const { return _intervalX; }
        double intervalY() const { return _intervalY; }

    public:
        /// Return the value at a raster position (override of pure virtual
        /// method).
        double value(double x, double y) const;

//        /// Return the range of values in the raster.
//        QwtInterval range() const { return _ampRange; };

        /// Calculates the amplitude range of the image data.
        void _findAmpRange();

    private:
        std::vector<float> _data;
        unsigned _sizeX;
        unsigned _sizeY;
        double _intervalX;
        double _intervalY;
        QwtInterval _ampRange;
        QwtInterval _xRange;
        QwtInterval _yRange;
};

} // namespace spectrum
#endif // IMAGE_PLOT_DATA_H
